// Appendix2.5
log using Appendix2.5.log, replace
use "C:\Users\sbstjp\OneDrive - Cardiff University\Nationscapedataset.dta" // Tausanovitch, Chris and Lynn Vavreck. 2020. Democracy Fund + UCLA Nationscape, October 10-17, 2019 (version 20200814). Retrieved from [URL].  Date accessed: March 09, 2025.

keep gender age education household_income race_ethnicity weight ideo5 statements_gender_identity reparations group_favorability_blm group_favorability_undocumented start_date

// Social justice scale
*Drop missing values
replace statements_gender_identity=. if statements_gender_identity>4 
replace group_favorability_blm=. if group_favorability_blm>4 
replace reparations=. if reparations>2 
replace group_favorability_undocumented=. if group_favorability_undocumented==999 

*Rename so shorter
rename group_favorability_blm blm
rename group_favorability_undocumented undocumented
rename statements_gender_identity genderidentity

*Reverse variables so social justice is coded high
foreach var in blm reparations undocumented {
    qui sum `var'
    local max_value = r(max)
    gen r`var' = `max_value' + 1 - `var'
}

*Standardize items in the scale from 1-2 - this avoids 0, for reasons outlined in next step
foreach var in rblm rreparations rundocumented genderidentity {
    summarize `var'
    gen s`var' = 1 + (`var' - r(min)) / (r(max) - r(min))
}

*At this point, the scale has a Cronbach's Alpha of 0.78

* Replace missing values with 0 for the specified variables - this is necessary as Stata doesn't add up missing values
foreach var in srblm srreparations srundocumented sgenderidentity {
    replace `var' = 0 if missing(`var')
}

* Initialize the total score and the count of non-zero responses
gen total_scoreSJV = 0
gen count_nonzeroSJV = 0

* Add each variable to the total scale score and count it if non-zero
foreach var in srblm srreparations srundocumented sgenderidentity {
    replace total_scoreSJV = total_scoreSJV + `var'
    replace count_nonzeroSJV = count_nonzeroSJV + (`var' != 0)
}

* Calculate the average score, avoiding division by zero
gen SocJusValues = .
replace SocJusValues = total_scoreSJV / count_nonzeroSJV if count_nonzeroSJV > 0

// Demographic variables

*Drop missing values
replace ideo5=. if ideo5==999

*Reverse code gender 
egen maxval = max(gender)
gen FemaleGender = maxval + 1 - gender
drop maxval

*Create dummies
gen Graduate=.
replace Graduate=0 if inrange(education, 1, 7)
replace Graduate=1 if inrange(education, 8, 11)

gen BIPOC=. 
replace BIPOC=0 if race_ethnicity==1
replace BIPOC=1 if inrange(race_ethnicity, 2, 15)

// Standardize
egen Income = std(household_income)
egen Age = std(age)

// Regressions

regress SocJusValues Age BIPOC FemaleGender Graduate Income if quarter(dofc(start_date)) == 4 & year(dofc(start_date)) == 2020 [pweight=weight], robust 
eststo
regress SocJusValues Age BIPOC FemaleGender Graduate Income if quarter(dofc(start_date)) == 4 & year(dofc(start_date)) == 2020  & ideo5<3 [pweight=weight], robust
eststo
regress SocJusValues Age BIPOC FemaleGender Graduate Income if quarter(dofc(start_date)) == 3 & year(dofc(start_date)) == 2019 [pweight=weight], robust // 2019 Q3 (Jul-Sep 2019)
eststo
regress SocJusValues Age BIPOC FemaleGender Graduate Income if quarter(dofc(start_date)) == 4 & year(dofc(start_date)) == 2019 [pweight=weight], robust // 2019 Q4 (Oct-Dec 2019)
eststo
regress SocJusValues Age BIPOC FemaleGender Graduate Income if quarter(dofc(start_date)) == 1 & year(dofc(start_date)) == 2020 [pweight=weight], robust // 2020 Q1 (Jan-Mar 2020)
eststo
regress SocJusValues Age BIPOC FemaleGender Graduate Income if quarter(dofc(start_date)) == 2 & year(dofc(start_date)) == 2020 [pweight=weight], robust // 2020 Q2 (Apr-Jun 2020)
eststo
regress SocJusValues Age BIPOC FemaleGender Graduate Income if quarter(dofc(start_date)) == 3 & year(dofc(start_date)) == 2020 [pweight=weight], robust // 2020 Q3 (Jul-Sep 2020)
eststo
esttab 

log close

eststo clear
esttab using "Appendix2.5.rtf", ///
    b(3) se(3) ///
    star(* 0.05 ** 0.01 *** 0.001) ///
    coeflabels(_cons "Constant") ///
    nonumbers replace
	
// Alternative specification
ologit SocJusValues Age BIPOC FemaleGender Graduate Income if quarter(dofc(start_date)) == 4 & year(dofc(start_date)) == 2020 [pweight=weight], robust 


